package jaux.tank.generator.jd.components;

import java.util.function.Consumer;

import javax.swing.JCheckBox;
import javax.swing.JComponent;

public class JdCheckBox extends JdLabeledInput<Boolean, Object>{

	

	private static final long serialVersionUID = 1L;
	private JCheckBox checkBox;
	
	public JdCheckBox(String label, Boolean defaultValue) {
		super(label, defaultValue);
	}
	
	@Override
	public JComponent createInputComponent(Object  params) {
		this.checkBox = new JCheckBox();
		return this.checkBox;
	}
	@Override
	public Boolean getValue() {
		return checkBox.isSelected();
	}

	@Override
	public void setValue(Boolean value) {
		checkBox.setSelected(value);
	}
	@Override
	public void setEditable(boolean b) {
		checkBox.setEnabled(b);		
	}

	@Override
	public void registerChangeHandler(Consumer<Boolean> handler) {
		checkBox.addItemListener(e -> handler.accept(getValue()));
	}
	
}
